﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace MyMusicPlay._4._0.ElementFactory
{
    public class ListViewItemFactory : ElementFactoryBase
    {
        public ListViewItemFactory(MainWindow main) : base(main)
        { }

        protected override Element CreateElement<Element>(Action<Element> action = null)
        {
            if (_styleByFocur == null)
            {
                InitializeStyle();
            }

            var element = base.CreateElement(action) as ListViewItem;
            //element.MouseEnter += (sender, e) => { (sender as ListViewItem).Style = _styleByFocur; };
            //element.MouseLeave += (sender, e) => { (sender as ListViewItem).Style = _styleByDefault; };

            return (element as Element)!;
        }

        private void InitializeStyle()
        {
            var focurColor = PlayApplication.GetModule<DispositionApp>().ReadDispositionOfItemBackColor();

            _styleByFocur = new();
            _styleByFocur.Setters.Add(new Setter() { Property = ListViewItem.BackgroundProperty, Value = focurColor.GetBush() });

            _styleByDefault = new();
            _styleByDefault.Setters.Add(new Setter() { Property = ListViewItem.BackgroundProperty, Value = SY_Library.Color.BackColor(255, 255, 255, 0) });
        }

        private Style _styleByFocur = null;
        private Style _styleByDefault = null;
    }
}
